package tcu.iot.gasmanage.api;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import tcu.iot.gasmanage.common.Result;
import tcu.iot.gasmanage.common.utils.QuerySwitchUtils;
import tcu.iot.gasmanage.entity.linechart.LineChartQuery;
import tcu.iot.gasmanage.service.LineChartService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api
@RestController
@RequestMapping("/lineChart")
@CrossOrigin
public class LineChartController {

    @Resource
    private LineChartService lineChartService;

    @ApiOperation(value = "/getData", notes = "获取图表所需数据")
    @GetMapping(value = "/getData")
    public Result FindOptions(HttpServletRequest request) {
        LineChartQuery lineChartQuery = JSON.parseObject(QuerySwitchUtils.QuerySwitch(request.getQueryString()), LineChartQuery.class);

        return lineChartService.getData(lineChartQuery);
    }
}
